﻿using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Serialization;

namespace MyAnimelistRecommender.DataObject
{
    public class Anime
    {
        public string Uri { get; set; }

        public string _Title;

        public string Title
        {
            get
            {
                return _Title;
            }
            set
            {
                _Title = value;
                GroupTitle = value;
            }
        }

        public int Score { get; set; }

        public bool IsActivated { get; set; }

        public string GroupTitle { get; set; }

        private ObservableCollection<Recommendation> _Recommends;

        public Anime()
        {
            IsActivated = true;
        }

        public ObservableCollection<Recommendation> Recommends
        {
            get
            {
                return _Recommends;
            }
            set
            {
                if (value != _Recommends)
                {
                    _Recommends = value;
                    if (value != null)
                    {
                        _Recommends.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_Recommends_CollectionChanged);
                        _Recommends.ToList().ForEach(x => x.Anime = this);
                    }
                }
            }
        }

        private void _Recommends_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Recommendation i in e.NewItems)
                {
                    i.Anime = this;
                }
            }
        }

        public bool Dropped { get; set; }

        public bool IsNotDropped
        {
            get { return !Dropped; }
        }

        [XmlIgnore]
        public System.Net.WebClient WebClient;

        public bool IsWorking { get; set; }
    }
}